/**
 * represent a Nurse type user
 * 
 *
 */

package source;

import java.util.Date;
import java.util.List;
import java.util.Map;
import activejdbc.Model;

public class Nurse extends Model {
	
	public Nurse() {
		super();
	}

	public Nurse(Map<String, String> values) {
		this.fromMap(values);
	}

	/**
	 * add a patient, set necessary fields, and return it
	 * 
	 * @param values	key-map, any values passed in, match them and fill in
	 * @return 			patient that is created
	 */
	public void addPatient(Map<String, String> values) {
		Patient p = new Patient(values);
		p.saveIt();
	}
	
	/**
	 * find a patient by username, then delete from database
	 * 
	 * @param values 	key-map, any values passed in, match them and find
	 */
	public void deletePatient(Map<String, String> values) {
		Patient aPatient = (Patient)Patient.findFirst("username = ?", values.get("username"));
		aPatient.delete();
	}
	
	/**
	 * find patient(s) by the parameter(s) and return the list of patient(s)
	 * 
	 * @param values 	key-map, any values passed in, match them to find
	 * @return 			list of Patient that are matched
	 */
	public Patient lookupPatient(Map<String, String> values) {
		if (values.containsKey("id"))
			return (Patient)Patient.findById(values.get("id"));
		else if (values.containsKey("username"))
			return (Patient)Patient.findById(values.get("username"));
		else
			return (Patient)Patient.findById(values.get("fullname"));
		//return (Patient)Patient.findFirst("username = ?", values.get("username"));
	}
	
	/**
	 * updates patient parameters
	 * 
	 * @param values 	key-map, any values passed in, match them to find
	 */
	public void updatePatient(Patient p, Map<String, String> values) {
		p.fromMap(values);
		p.saveIt();
	}
	
	/**
	 * create a treatment record with values passed in
	 * 
	 * @param values	key-map, any values passed in, match them and fill in
	 * @return			TreatmentRecord that is created
	 */
	
	public List<Patient> getAllPatients() {
		return Patient.findAll();
	}
	
	/**
	 * creates a new treatment record
	 * 
	 * @param values 	key-map, any values passed in, match them and fill in
	 */
	public void createTreatmentRecord(Map<String, String> values) {
		TreatmentRecord t = new TreatmentRecord(values);
		t.set("nurse_id", this.get("id"));
		t.saveIt();
	}
	
	// how to figure out today's date?
	/**
	 * find the list of appointments with today's date
	 * 
	 * @return			list of Appointment that are matched with today's date
	 */
	public List<Appointment> viewTodaysAppointments() {
		Date date = new Date();
		List<Appointment> appointments = Appointment.find("time = ?", date.getTime());
		return appointments;
	}

}
